﻿@{
    Layout = "/Views/Shared/_SubLayout.cshtml";
    ViewBag.Title = "所有帳戶";
}
<script>
    $(document).ready(function () {
        $.fn.metro.onPrevClick = function () {
            window.location = "/Home";
        };
        loadAccounts();
    });

    function changeAccount() {
        var id = $('.metro_grid_row.selected .accountID').html();

        if (id == undefined || id == '') {
            showMessage('請選擇需要修改的帳戶');
        }
        else {
            window.location = "/Home/AccountEdit?id=" + id;
        }
    }
</script>
<script id="metroGridRowTemplate" type="text/x-jquery-tmpl">
    <div class="metro_grid_row">
        <div class="metro_grid_cell hide"><div class="accountID">${ID}</div></div>
        <div class="metro_grid_cell"><div>${Name}</div></div>
        <div class="metro_grid_cell"><div>${EffectiveStr}</div></div>
        <div class="clear">
        </div>
    </div>
</script>
<script id="metroGridTemplate" type="text/x-jquery-tmpl">
    <div class="metro_grid">
        <div class="metro_grid_contain">
            <div class="metro_grid_header">
                <div class="metro_grid_column hide"><div>
                </div></div>
                <div class="metro_grid_column" data-width="200"><div>
                    使用者名稱</div></div>
                <div class="metro_grid_column" data-width="100"><div>
                    是否可用</div></div>
                <div class="clear">
                </div>
            </div>
            <div class="metro_grid_rows">
                {{tmpl(List) "#metroGridRowTemplate"}}
            </div>
        </div>
    </div>
</script>
<div id="AccountMgt">
    <div class="metro_toolbar">
        <div class="metro_input_contain">
            <a class="metro_input_btn" href="/Home/AccountEdit">新增帳戶</a>
            <a class="metro_input_btn" onclick="changeAccount();">修改帳戶</a>
        </div>
    </div>
</div>
<script>
    function loadAccounts() {
        showLoading();
        var url = "/Home/GetAccounts";
        $.ajax({
            url: url,         //请求链接 
            dataType: "json",
            success: function (result) {
                $('#metroGridTemplate').tmpl(result).appendTo($('#AccountMgt'));
                $('.metro_grid').metro_grid();

                hideLoading();
            }
        });
    }
</script>
